package com.dark;

import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests;
import static com.google.common.base.Preconditions.*;
/**
 * Created by tengxue on 16-6-15.
 */
@ContextConfiguration(locations = {"classpath*:applicationContext.xml"})
public class RedisStringDemo  extends AbstractJUnit4SpringContextTests {


    @Autowired
    private StringRedisTemplate stringRedisTemplate;

    @Test
    public void testAddString() {
        stringRedisTemplate.opsForValue().set("test1","test");
        System.out.println("ok");
    }

    @Test
    public void testGetString() {
        String value=stringRedisTemplate.opsForValue().get("test1");
        System.out.println("the value is :" + value);
        checkArgument(value.equals("test"), "the value is invalidate!");
    }

    @Test
    public void testStringIncrement() {
        stringRedisTemplate.opsForValue().set("age", "12");
        stringRedisTemplate.opsForValue().increment("age", 1);
        String value=stringRedisTemplate.opsForValue().get("age");
        System.out.println("the value is :"+value);
        checkArgument(value.equals("13"), "the value is invalidate!");
        stringRedisTemplate.opsForValue().increment("age", -10);
        value=stringRedisTemplate.opsForValue().get("age");
        System.out.println("the value is :" + value);
        checkArgument(value.equals("3"), "the value is invalidate!");
    }




}
